<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBClientView_glossary extends KBClientView_common
{

	function &execute(&$manager) {
		
		$this->home_link = true;
		$this->meta_title = $this->msg['glossary_msg'];
		
		$data = $this->getTop($manager, $this->msg['glossary_msg'], true);
		$data .= $this->getGlossaryList($manager);
		
		return $data;
	}
	
	
	function getGlossaryList($manager) {
		
		$tpl = &new tplTemplatez($this->template_dir . 'glossary_list.html');
		

/*
		$letters = array();
		@$_letter = $_GET['let'];
		foreach($this->stripVars($manager->getGlossaryLetters()) as $k => $v) {
			$letter = strtoupper(substr($v, 0, 1));
			$letters[$letter] = $letter;
		}
		
		if(count($letters) > 1 || $_letter) {
			
			$letter_param = ($this->controller->mod_rewrite) ? '?let=%s' : '&let=%s'; 
			$tpl->tplSetNeededGlobal('letters');
			
			foreach($letters as $letter) {

				$a['letter'] = $letter;
				$a['letter_link'] = $this->_getLink('glossary') . sprintf($letter_param, urlencode($letter));
				$a['letter_class'] = ($this->msg_id == $letter) ? '' : '';
				$tpl->tplParse($a, 'letter');
			}
			
			$tpl->tplAssign('all_letter_link', $this->_getLink('glossary'));
		}		
		
		if($_letter) {
			$_letter = (substr(urldecode($_letter), 0, 1));
			$manager->setSqlParams("AND phrase LIKE '$_letter%'");
		}	
*/	
		
		
		$rows = $this->stripVars($manager->getGlossaryDefinitions());
		foreach($rows as $k => $v) {
			
			$letter = strtoupper(substr($k, 0, 1));
			$letters[$letter] = $letter;
			
			$v['phrase'] = $k;
			$tpl->tplParse($v, 'row');
		}
		

		$tpl->tplAssign('base_href', $this->conf['client_home_path']);
		$tpl->tplAssign('print_link', $this->_getLink('print', '', '', 'glossary'));
		
		$tpl->tplParse($this->msg);
		return $tpl->tplPrint(1);
	}
	
	
	function getLetterFilter(&$tpl, $vars) {
			
		//letter filter
		$get = $vars;
		unset($get['letter']);
		$str = http_build_query($get);
		
		foreach(range('a', 'z') as $k => $v) {
			$a['letter'] = strtoupper($v);
			$a['letter_link'] = $_SERVER['PHP_SELF'] . '?' . $str . '&letter=' . $v;
			$a['letter_class'] = (@$vars['letter'] == $v) ? 'tdSubTitle' : '';
			
			$tpl->tplParse($a, 'letter');
		}
	
	
		$ar = $vars; unset($ar['letter']);
		$tpl->tplAssign('all_letter_link', $_SERVER['PHP_SELF'] . '?'. http_build_query($ar));
		//$tpl->tplAssign('all_letter_msg', 'value');
	
		
		if(isset($vars['letter'])) {
			$sql = "phrase LIKE '". $vars['letter'] . "%'";
		} else {
			$sql = '1';
		}
		
		return $sql;
	}	
}
?>